def is_prime(n):
    if n < 2:
        return False
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            return False
    return True

def find_largest_prime(number):
    if len(str(number)) != 4:
        return 0
    
    digits = [int(d) for d in str(number)]
    
    largest_prime = 0
    
    for i in range(4):
        curr_num = int(''.join(map(str, digits[i:])))
        if is_prime(curr_num) and curr_num > largest_prime:
            largest_prime = curr_num
    
    return largest_prime

num = int(input("Введите четырехзначное натуральное число: "))
result = find_largest_prime(num)
print(result)